#include <stdio.h>
#include <stdlib.h>
#include  <unistd.h>
#include <string.h>


int main()
{
    int fds[2];
    char buffer[100];
    int len;

    if(pipe(fds)==-1)
        perror("pipe error"),exit(1);

    while(fgets(buffer,100,stdin))
    {
        len =strlen(buffer);
        if(write(fds[1],buffer,len)!=len)
        {
            perror("write perror");
            break;
        }
        memset(buffer,0x00,sizeof(buffer));

        len=read(fds[0],buffer,len);
        if(len==-1)
        {
            perror("read perror");
            break;
        }
        if(write(1,buffer,len)!=len)
        {
            perror("write to stdout perror");
            break;
        }
    }
    return 0;
}
